﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.ComponentModel;

namespace App6._10
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            _sysinfo = new SystemInfo();
            Binding binding = new Binding();
            binding.Source = _sysinfo;
            binding.Path = new PropertyPath("Temperature");
            text1.SetBinding(TextBlock.TextProperty, binding);
        }

        public void OnClick(object sender, RoutedEventArgs args)
        {
            _sysinfo.Temperature = 20;
        }

        public SystemInfo _sysinfo = null;
    }

    public class SystemInfo : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propName)
		{
			if (this.PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }

        double _temperature;

	    public double Temperature
        {
	        get{    return this._temperature;}
	        set
            {
                this._temperature=value;
                OnPropertyChanged("Temperature");
            }
        }
    }

}
